<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'FeedData_JS.jsp' starting page</title>
    <!-- 
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
 -->
<script type="text/javascript" src="./FusionWidgets/FusionCharts.js"></script>
<script type="text/javascript" src="./ui/js/jquery.js"></script>
<link href="assets/ui/css/style.css" rel="stylesheet" type="text/css" />
      <script type="text/javascript">				
        		function feedData(){
        		var TaskId = "${attr.taskId}";
        		var chartRef = FusionCharts("RealTimeArea");
        		
		 			var params = {
		        	  taskId : TaskId, 
		     		  };
			       $.ajax({
			   		type: "POST",
			   		url: "DataForRealTimeArea.action?ran="+Math.floor(Math.random()*10000),    //提交的地址
			   		data: params,	
			    	dataType:"text",            //ajax返回值设置为text（json格式也可用它返回，可打印出结果，也可设置成json）
			    	success: function(json){  
			    	var obj = $.parseJSON(json);  //使用这个方法解析json
			        var dataParameters = obj.dataParameters;  //dispatchResult是和action中定义的dispatchResult变量的get方法对应的
			       	//alert(dataParameters);
			       	//$("#data").html(dataParameters);
			        chartRef.feedData(dataParameters);
			    	},
			    	error: function(json){
			    		alert("返回数据失败！！");
			   		 }
			    	});
					setTimeout("feedData()", 60000);
		 		}

	</script>
</head>
<body onload="feedData()">
<div style="height: 100%;width: 100%;float: left;">
	<div id="left" style=" width: 550px;float: left;">
		<div >
			<input type="button" name="Submit" onclick="javascript:history.back(-1);" value="返回任务列表">
		</div>
		<div id="chartdiv" style="margin: 0 auto; width: 550px;height: 400px;float: left;">
		</div>
	</div>
	<div id="right" style="height: 400px;width:300px;float: left;margin-top: 25px;margin-left: 10px;">
	</div>	
</div>

<script type="text/javascript">
	var kindName = "${attr.taskKind}";
   var chart = new FusionCharts("./FusionWidgets/RealTimeArea.swf", "RealTimeArea", "550", "400", "0", "1");
   if(kindName=="CPU"){
   		chart.setXMLData("<chart caption='CPU实时使用率折线图' \n\
		numberSuffix='%' yAxisMaxValue='100' yAxisMinValue='0'  xAxisName='时间' showRealTimeValue='1' labelDisplay='Rotate' slantLabels='1' numDisplaySets='15' canvasBottomMargin='150'	>\n\
		<categories>\n\
		</categories>\n\
		<dataset seriesName='CPU使用率' showValues='0'>\n\
		</dataset>\n\
		<styles>\n\
			<definition>\n\
			<style type='font' name='captionFont' size='14' />\n\
			</definition>\n\
			<application>\n\
				<apply toObject='Caption' styles='captionFont' />\n\
				<apply toObject='Realtimevalue' styles='captionFont' />\n\
			</application>\n\
			</styles>\n\
		</chart>");
   }
   if(kindName=="memory"){
   		chart.setXMLData("<chart caption='内存实时使用率折线图' \n\
		numberSuffix='%' yAxisMaxValue='100' yAxisMinValue='0' xAxisName='时间' showRealTimeValue='1' labelDisplay='Rotate' slantLabels='1' numDisplaySets='15' canvasBottomMargin='150'>\n\
		<categories>\n\
		</categories>\n\
		<dataset seriesName='内存使用率' showValues='0'>\n\
		</dataset>\n\
		<styles>\n\
			<definition>\n\
			<style type='font' name='captionFont' size='14' />\n\
			</definition>\n\
			<application>\n\
				<apply toObject='Caption' styles='captionFont' />\n\
				<apply toObject='Realtimevalue' styles='captionFont' />\n\
			</application>\n\
			</styles>\n\
		</chart>");
   }
   chart.render("chartdiv");
</script>

</body>
</html>
